package br.com.timecardforpeon.domain.contentvalue;

import br.com.timecardforpeon.domain.Entry;
import br.com.timecardforpeon.util.Util;

public class EntryContentValues extends TimeCard4PeonContentValues<Entry> {

	@Override
	public TimeCard4PeonContentValues<Entry> create(Entry entry) {
		
		this.checkIn(entry);
		this.checkOut(entry);
		
		if (entry.getDay() != null) {
			this.values.put(Entry.COLUMN_DAY_ID, entry.getDay().getId());
		}
		
		return this;
	}

	private void checkIn(Entry entry) {
		
		if (entry.getCheckIn() == null) {
			this.values.put(Entry.COLUMN_CHECK_IN, "");
			return;
		}
		
		this.values.put(Entry.COLUMN_CHECK_IN, Util.dateTimeToString(entry.getCheckIn()));
	}

	private void checkOut(Entry entry) {
		
		if (entry.getCheckOut() == null) {
			this.values.put(Entry.COLUMN_CHECK_OUT, "");
			return;
		}
		
		this.values.put(Entry.COLUMN_CHECK_OUT, Util.dateTimeToString(entry.getCheckOut()));
	}
}